package com.gilgamesh.im;

import com.gilgamesh.im.common.ServerBootConfiguration;
import com.gilgamesh.im.handle.server.MsgHandle;
import com.gilgamesh.im.handle.server.ServerMsgHandlePool;

import java.net.ServerSocket;
import java.net.Socket;

/**
* 即时通信的服务器端
**/
public class IMServer {

    public static void main(String[] args) throws Exception{
        /**
        * 服务端启动监听,注册监听端口
        **/
        ServerSocket serverSocket = new ServerSocket(ServerBootConfiguration.SERVERPORT);
        while(true){
            /**
            * 获取被监听到的客户端的套接字
             * get the socket of the monitored client
            **/
            Socket socket = serverSocket.accept();
            /**
            * 监听到客户端消息就将消息委托给消息处理线程池
            **/
            ServerMsgHandlePool.getExecutorService().execute(new MsgHandle(socket));
        }
    }
}
